package com.zerdoor.service.impl;

import com.zerdoor.dao.UserDao;
import com.zerdoor.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2014/11/20.
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public List<Map<String, Object>> getUsers(Map<String, Object> map) {

        List<Map<String, Object>> list = userDao.getUsers(map);
        List<Map<String, Object>> skills = userDao.getUserSkill();
        //重置技能
        for(Map<String, Object> m :list){
            if(m.get("skill") != null && !"".equals(m.get("skill").toString())){
                StringBuffer skillName=new StringBuffer();
                String[] arr = m.get("skill").toString().split(",");
                for(int i=0;i<arr.length;i++){
                    for(Map<String, Object> s : skills){
                        if(Integer.parseInt(arr[i]) == Integer.parseInt(s.get("minor_id").toString())){
                            skillName.append(s.get("skill").toString());
                            if(i != (arr.length-1)){
                                skillName.append(",");
                            }
                            break;
                        }
                    }
                }
                m.put("skillName",skillName.toString());

            }
        }
        return list;
    }

    @Override
    public List<Map<String, Object>> getUserByUserId(int userId) {
        return userDao.getUserByUserId(userId);
    }

    /**
     * 获取艺术家等级
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> getArtistLevels() {
        return userDao.getArtistLevels();
    }

    /**
     * 改变艺术家等级
     *
     * @param map
     * @throws Exception
     */
    @Override
    public void updateArtisLevel(Map<String, Object> map) throws Exception {
        userDao.updateArtisLevel(map);
    }

    /**
     * 身份认证
     *
     * @param userId 用户编号
     * @throws Exception
     */
    @Override
    public void updateNameAuth(int userId) throws Exception {
        userDao.updateNameAuth(userId);
    }
}
